const app = getApp()
const $api = require('../../utils/api.js').API;
Page({
    data: {
        avatarUrl:'',
        role:0,
        nickName:'',
        count:[]
    },
    onShow: function() {
        this.login()
    },
    jump:function(e){
        var name = e.currentTarget.dataset.name;
        wx.navigateTo({
            url:name
        })
    },
    getCount:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid')}
        $api.get('information/center',data).then(res =>{
            if(res.data.code == 1){
                wx.hideLoading()
                that.setData({
                    count:res.data.data
                })
            }
        })
    },
    onShareAppMessage: function(){
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    },
    login:function(){
        if(!wx.getStorageSync('uid')){
            //没有缓存 跳转授权页面
            wx.navigateTo({
                url:'/pages/index/guide'
            })
        }else{
            this.setData({
                'avatarUrl':wx.getStorageSync('avatarUrl'),
                'nickName':wx.getStorageSync('nickName'),
                'role':wx.getStorageSync('role')
            })
            //验证手机号码是否存在
            this.checkphone();
        }
    },
    //查询手机号  是否注册
    checkphone:function(){
        var data = {
            'uid':wx.getStorageSync('uid')
        }
        var that = this
        $api.post('member/phone',data).then(res =>{
            if(res.data.code !== 1){
                wx.navigateTo({
                    url:'/pages/index/phone'
                })
                return;
            }
            wx.showLoading()
            that.getCount();
        })
    }
});